import type { UserResponse, UserInfoResponse, UserEditInfo } from "@/types/data"
import { http } from "@/utils/http"
import { RootThunkAction } from "@/types/store"

export const getUserProfile = (): RootThunkAction => {
    return async dispatch => {
     const res =  await http.get('/user') as UserResponse
     dispatch({ type: 'user/profile', payload: res.data  })
    }
}
export const getUserInfo = (): RootThunkAction => {
    return async dispatch => {
      const res = await http.get('/user/profile') as UserInfoResponse
      dispatch({ type: 'user/userinfo', payload: res.data })
    }
}
// 修改用户资料
export  const updateUserInfo = (values: UserEditInfo): RootThunkAction  => {
   return async dispatch => {
     await http.patch('/user/profile', values)
     dispatch({ type:'user/updateProfile', payload:  values }) // 更新用户内容
   }
}